#pragma once

#include "ddraw.h"
#include "DD_ImgCfg.h"
#include "DD_AnalyCfg.h"
#include "DDAutoDelete.h"

enum
{
	eBuffer_Back  = 0x01,
	eBuffer_Back2 = 0x02,
	eBuffer_Front = 0x04,
};

class DDAnalyDisp
{
public:
	DDAnalyDisp(void);
	~DDAnalyDisp(void);

public:
	int SetParent(HWND hWnd,zkScreenMon *pScreen=NULL);
	void SetBack2(bool bBack2 = true);

public:
	int SetDisplayPalette(int nDark=0, int nBright=65535,int nBpp=18);
	int Negative();
	void SetUpDown(bool bUpDown = true);
	
public:
	int SetDisplayData(zkImgBitInfo *pBitInfo,void *pVoid = NULL);
	int SetDisplayDst(void *pVoid = NULL);

public:
	int RegOnDrawCallBack(AnalyOnDrawCallBackFun funCallBack,DWORD dwContext,void *pContext);

public:
	int ClearScreen(int nBuffer = 0x03); //0x01,0x02,0x03:all,0x07


private:
	void UnInitFront();
	void UnInitBack();
	int  CreateFront();
	int  CreateBack(int nWidth,int nHeight);

	int  CreateBack2(int nWidth,int nHeight);
	void UnInitBack2();

	int  CheckDDraw(int nWidth,int nHeight);

private:
	int  Set16BitData(zkImg16BitInfo *pBitInfo);
	int  Set8BitData(BITMAPINFOHEADER *pBitInfo);
	int  Set32FBitData(zkImg32FBitInfo *pBitInfo);



public:
	HWND         m_hWnd;
	zkScreenMon  m_xScreen;

public:
	int m_nDispW,m_nDispH;
	int m_nDark,m_nBright,m_nBpp;

private:
	int m_nWidth,m_nHeight;


private:
	int   m_nGrayLevel;
	BYTE *m_pLUTxTo8;

private:
	bool m_bUpDown;
	bool m_bBack2;

private:
	LPDIRECTDRAW7        m_pDD;
	LPDIRECTDRAWSURFACE7 m_pDDSFront;
	LPDIRECTDRAWSURFACE7 m_pDDSBack;
	LPDIRECTDRAWCLIPPER  m_pcClipper;

	int                  m_nPixelSize;

public:
	LPDIRECTDRAWSURFACE7 m_pDDSBack2;
	int m_nWidth2,m_nHeight2;

	DWORD                  m_dwContext;
	void                  *m_pContext;
	AnalyOnDrawCallBackFun m_funOnDrawCallBack;

private:
	DDCriticalSection  m_xSect;

};
